package com.example.books.program

/**
 * @title: Complex
 * @projectName bigdata
 * @Version: 1.0
 * @description: 云算法重载
 * @author leali
 * @date 2022/5/31 23:09
 */
class Complex(val real: Int, val imaginary: Int) {

  def +(operand: Complex): Complex = {
    println("Calling +")
    new Complex(real + operand.real, imaginary + operand.imaginary)
  }

  def *(operand: Complex): Complex = {
    println("Calling *")
    new Complex(real * operand.real - imaginary * operand.imaginary, real * operand.imaginary + imaginary * operand.real)
  }

  override def toString: String = {
    s"$real${if (imaginary > 0) "+" else ""}${if (imaginary != 0) imaginary + "i" else ""}"
  }
}
